package com.ruoyi.quartz.task;

import com.alibaba.druid.pool.DruidDataSource;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
 * 定时任务调度测试
 *
 * @author ruoyi
 */
@Component("myTask")
public class myTask
{
    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams()
    {
        System.out.println("执行无参方法");
    }

    public void myTask() { System.out.println("get newest file test");}

    @Autowired
    private DruidDataSource druidDataSource;

    public void getUsersData() {
        String sql = "SELECT create_time FROM sys_job_log";
        try (Connection conn = druidDataSource.getConnection();
             PreparedStatement stmt = conn.prepareStatement(sql);
             ResultSet rs = stmt.executeQuery()) {

            while (rs.next()) {
                String createTime = rs.getString("create_time");
                System.out.println("create_time: " + createTime);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
